<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import request from '../../utils/request'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      count: {
        certificationAudited: null,
        certificationNotAudited: null,
        projectReviewed: null,
        projectNotAudited: null
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    getCount() {
      request.get("/project/project/count").then(res => {
        this.count = res.data
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['用户认证已审核', '用户认证未审核', '项目已审核', '项目未审核']
        },
        series: [
          {
            name: 'WEEKLY WRITE ARTICLES',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '38%'],
            data: [
              { value: this.count.certificationAudited, name: '用户认证已审核' },
              { value: this.count.certificationNotAudited, name: '用户认证未审核' },
              { value: this.count.projectReviewed, name: '项目已审核' },
              { value: this.count.projectNotAudited, name: '项目未审核' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
      })
    },
    initChart() {
      

      
    }
  },
  created() {
    this.getCount()
  }
}
</script>
